Description:
CQS checks that methods that return a value do not modify the state of the declaring object. The methods used to query the state of an object must be different from the methods used to perform commands (change the state of the object).
Incorrect:
public class Container {
private int size;
public int Grow(int delta) {
size += delta;
...
return size;
}
}
Correct:
public class Container {
private int size;
public void Grow(int delta) {
size += delta;
...
}
public int Size() {
return size;
}
}
Refactoring: